/*
 * @Author: chunlai
 * @Date: 2025-04-10 14:47:37
 * @LastEditTime: 2025-08-27 16:46:17
 * @LastEditors: minsheng_insurance_agency_zhoucl
 * @FilePath: \02.bldinsure\src\config\const.js
 * @Description:常量配置
 */
export default {
  /*常量文本*/
  baseDomain: "/app_h5/bldinsure",
  baseWxscDomain: "/app_h5/testinsurance/bldinsure",
  /*校验函数*/
  idCard: (value) => {
    return /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/.test(
      value
    );
  },
  mobile: (value) => {
    return /^1[3-9]\d{9}$/.test(value);
  },
  email: (value) => {
    return /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/.test(
      value
    );
  },
  date: (value) => {
    return !/Invalid|NaN/.test(new Date(value).toString());
  },
  linkUrl: (value) => {
    return /http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w-.\/?%&=]*)?/.test(value);
  },
  // 中文
  chinese: (value) => {
    let reg = /^[\u4e00-\u9fa5]+$/gi;
    return reg.test(value);
  },
  //英文或者数字
  engNum: (value) => {
    let reg = /^[0-9a-zA-Z]*$/g;
    return reg.test(value);
  },
  // 固定电话
  landline: (value) => {
    let reg = /^\d{3,4}-\d{7,8}(-\d{3,4})?$/;
    return reg.test(value);
  },
  smsCode: function (value, len = 6) {
    return new RegExp(`^\\d{${len}}$`).test(value);
  },
  string: (value) => {
    const valType = Object.prototype.toString
      .call(value)
      .slice(8, -1)
      .toLowerCase();
    return valType === "string";
  },
  object: (value) => {
    return Object.prototype.toString.call(value) === "[object Object]";
  },
  array: (value) => {
    if (typeof Array.isArray === "function") {
      return Array.isArray(value);
    } else {
      return Object.prototype.toString.call(value) === "[object Array]";
    }
  },
  empty: (data) => {
    const valType = Object.prototype.toString
      .call(data)
      .slice(8, -1)
      .toLowerCase();
    if (valType === "object") {
      return Object.keys(data).length === 0;
    } else if (valType === "array") {
      return data.length === 0;
    } else if (valType === "string") {
      return data === "";
    }
  },
  /*短函数*/
  strAdd0: (str, num = 2) => String(str).padStart(num, "0"),
  domainUrl: () => {
    return window.location.origin + window.location.pathname;
  },
  delNull: (obj) => {
    for (const key in obj) {
      if (!obj[key]) {
        delete obj[key];
      }
    }
    return obj;
  },
  // demoValide: (value)=> {},
};
